using System;
using UnityEditor;
using UnityEngine;

namespace UnityXEditor
{
    [Serializable]
    public class PlatformSettings
    {
        public WindowsToolSettings windows { get { return m_Windows; } }
        [SerializeField]
        private WindowsToolSettings m_Windows = new WindowsToolSettings();

        public MacOSToolSettings macOS { get { return m_MacOS; } }
        [SerializeField]
        private MacOSToolSettings m_MacOS = new MacOSToolSettings();

        public LinuxToolSettings linux { get { return m_Linux; } }
        [SerializeField]
        private LinuxToolSettings m_Linux = new LinuxToolSettings();

        public AndroidToolSettings android { get { return m_Android; } }
        [SerializeField]
        private AndroidToolSettings m_Android = new AndroidToolSettings();

        public iOSToolSettings iOS { get { return m_iOS; } }
        [SerializeField]
        private iOSToolSettings m_iOS = new iOSToolSettings();

        public WebGLToolSettings webGL { get { return m_WebGL; } }
        [SerializeField]
        private WebGLToolSettings m_WebGL = new WebGLToolSettings();

        private int index = -1;
        private string[] names = new string[] { "Windows", "MacOS", "Linux", "Android", "iOS", "WebGL" };
        private void InitTarget()
        {
            if (index < 0)
            {
                switch (EditorUserBuildSettings.activeBuildTarget)
                {
                    case BuildTarget.StandaloneWindows:
                    case BuildTarget.StandaloneWindows64:
                        index = 0;
                        break;
                    case BuildTarget.StandaloneOSX:
                        index = 1;
                        break;
                    case BuildTarget.StandaloneLinux64:
                        index = 2;
                        break;
                    case BuildTarget.Android:
                        index = 3;
                        break;
                    case BuildTarget.iOS:
                        index = 4;
                        break;
                    case BuildTarget.WebGL:
                        index = 5;
                        break;
                    default:
                        index = 0;
                        break;
                }
            }
        }
        public void OnGUI()
        {
            InitTarget();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            switch (index = GUILayout.Toolbar(index, names))
            {
                case 0:
                    m_Windows.OnGUI();
                    break;
                case 1:
                    m_MacOS.OnGUI();
                    break;
                case 2:
                    m_Linux.OnGUI();
                    break;
                case 3:
                    m_Android.OnGUI();
                    break;
                case 4:
                    m_iOS.OnGUI();
                    break;
                case 5:
                    m_WebGL.OnGUI();
                    break;
                default:
                    break;
            }
            EditorGUILayout.EndVertical();
        }
        public void Update()
        {
            m_Windows.Update();
            m_MacOS.Update();
            m_Linux.Update();
            m_Android.Update();
            m_iOS.Update();
            m_WebGL.Update();
        }
    }
}